from tablewindow import TableWindow
import time

logs = []
log_window = None


def log(text):
    text = unicode(text)
    if log_window is not None:
        if logs:
            for tm, txt in logs:
                log_window.log(tm, txt)
            del logs[:]
        log_window.log(time.strftime('%H:%M:%S'), text)
    else:
        logs.append([time.strftime('%H:%M:%S'), text])
        

class LogWindow(TableWindow):

    def __init__(self, parent=None):
        super(LogWindow, self).__init__(parent, ['Time', 'Info'])
        self.setWindowTitle('Log')
        global log_window
        log_window = self
        
    def log(self, time, text):
        self.add_item(time, text)
        
